/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DBLayer;

import ModelLayer.Product;
import Prototypes.DataLayer;
import Prototypes.ProductResultSetModelBinder;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Moulde
 */
public class DBProductContainer extends DataLayer implements IProductContainer
{
    public DBProductContainer()
    {
        super();
    }

    public Product getProduct(int productID)
    {
        try
        {
            String sql = "SELECT * FROM WSProduct WHERE ProductID = " + productID;
            Statement statement = dbConnection.createStatement();
            ResultSet results = statement.executeQuery(sql);
            ProductResultSetModelBinder binder = new ProductResultSetModelBinder();

            return binder.BindModel(results);
        }
        catch (SQLException ex)
        {
            Logger.getLogger(DBProductContainer.class.getName()).log(Level.SEVERE, null, ex);
        }

        return null;
    }

    public ArrayList<Product> getProducts()
    {
        try
        {
            String sql = "SELECT * FROM WSProduct";
            Statement statement = dbConnection.createStatement();
            ResultSet results = statement.executeQuery(sql);
            ProductResultSetModelBinder binder = new ProductResultSetModelBinder();

            return binder.BindModels(results);
        }
        catch (SQLException ex)
        {
            Logger.getLogger(DBProductContainer.class.getName()).log(Level.SEVERE, null, ex);
        }

        return null;
    }
}
